const AlipaySdk = require('alipay-sdk').default
const AlipayFormData = require('alipay-sdk/lib/form').default


const RateModel = require("../../models/RateModel")
// const Email = require("../../email/email")
const { sendMail } = require("../../email/email");

const RateService ={
    
    add:async({propname,propnumber,propemail,building,roomnumber,basics,extend,tmoney,editTime,ispay})=>{
        return RateModel.create({
            propname,propnumber,propemail,building,roomnumber,basics,extend,tmoney,editTime,ispay,
        })
    },

    getList:async({id})=>{//{}是查询所有记录，【】是要的字段
        return id?RateModel.find({_id:id},["propname","propnumber","propemail","tmoney","ispay"]): 
        RateModel.find({},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"])
    },
    getList2:async({id})=>{//{}是查询所有记录，【】是要的字段
        return id?RateModel.find({_id:id,ispay:0},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"]): 
        RateModel.find({ispay:0},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"])
    },
    getList3:async({id})=>{//{}是查询所有记录，【】是要的字段
        return id?RateModel.find({_id:id,ispay:1},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"]): 
        RateModel.find({ispay:1},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"])
    },
    getListdata:async(data)=>{
        // console.log("ser:",data)
        // ${data}
        return RateModel.find({editTime: {"$gte": `2023-${data}-1`, "$lte": `2023-${data}-31`}},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"])
    },
    
    searchGetList:async({id})=>{//{}是查询所有记录，【】是要的字段
        return id?RateModel.find({_id:id,ispay:1},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"]): 
        RateModel.find({ispay:1},["propname","propnumber","propemail","building","roomnumber","tmoney","editTime","ispay"])
    },
    delList:async ({_id})=>{
        return RateModel.deleteOne({_id})
    },
    putList:async(body)=>{//{}是查询所有记录，【】是要的字段
        return RateModel.updateOne({_id:body._id},body)
    },
    email:async(body)=>{//{}是查询所有记录，【】是要的字段
        return sendMail(`${body.propemail}`,'物业缴费提醒',`<span>你好${body.propname}业主，您这个月的物业费为：${body.tmoney}请尽快缴费</span>`)
    },
    

}

module.exports =RateService